package com.yingjie.yingjieorder.service.impl;


import com.yingjie.commonbase.commons.DateUtil;
import com.yingjie.commonbase.commons.ReturnObject;
import com.yingjie.commonbase.model.Couples;
import com.yingjie.yingjieapi.openFeign.CouplesFeign;
import com.yingjie.yingjieorder.common.OrderStatus;
import com.yingjie.yingjieorder.dto.SubimtOrderDTO;
import com.yingjie.yingjieorder.mapper.OrderMapper;
import com.yingjie.yingjieorder.model.Order;
import com.yingjie.yingjieorder.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

/**
* @author Administrator
* @description 针对表【order(订单表)】的数据库操作Service实现
* @createDate 2025-03-09 15:15:02
*/
@Service
public class OrderServiceImpl implements OrderService{


    @Resource
    private OrderMapper orderMapper;
    @Resource
    private CouplesFeign couplesFeign;
    @Override
    public Integer subimtOrder(SubimtOrderDTO subimtOrderDTO,Integer userId) {
        Order order = new Order();
        Date cookTime = DateUtil.TimeToDateExample(subimtOrderDTO.getCookTime());
        order.setCookTime(cookTime);
        order.setOrderDes(subimtOrderDTO.getOrderDes());
        order.setTotalPrice(subimtOrderDTO.getTotalPrice());
        order.setCreatedAt(new Date());
        order.setUserId(userId);
        order.setOrderUuid(UUID.randomUUID().toString());
        order.setOrderStatus(OrderStatus.AWAIT_ING);
        //获取情侣信息
        ReturnObject<Couples> couplesInfo = couplesFeign.getCouplesInfo(userId);
        Couples result = couplesInfo.getResult();
        order.setToUserId(result.getToUserId());
        Integer res = orderMapper.subimtOrder(order);
        return order.getOrderId();
    }

    @Override
    public ArrayList<Order> placeOrderList(Integer userId) {
        return orderMapper.placeOrderList(userId);
    }
    @Override
    public Integer placeOrderListCount(Integer userId) {
        return orderMapper.placeOrderListCount(userId);
    }

    @Override
    public Order getOrderDetail(Integer orderId) {
        return orderMapper.getOrderDetail(orderId);
    }

    @Override
    public ArrayList<Order> acceptOrderList(Integer userId) {
        return orderMapper.acceptOrderList(userId);
    }

    @Override
    public Integer acceptOrderListCount(Integer userId) {
        return orderMapper.acceptOrderListCount(userId);
    }

    @Override
    public Integer acceptOrder(Integer orderId) {
        Order order = new Order();
        order.setOrderStatus(OrderStatus.TAKE_ORDER);
        order.setUpdatedAt(new Date());
        order.setOrderId(orderId);
        return orderMapper.acceptOrder(order);
    }

    @Override
    public Integer finishOrder(Integer orderId) {
        Order order = new Order();
        order.setOrderStatus(OrderStatus.FINISH);
        order.setFinishTime(new Date());
        order.setOrderId(orderId);
        return orderMapper.finishOrder(order);
    }
}




